<?php
namespace Admins\Model;
use Think\Model;
class AjaxModel extends Model {
protected $tableName = 'paystatus';
	public function PayEd($goodsid,$ordernumber,$qun)
	{
		//think_paystatus 先判断这个表示没有数据，才进行下一步，如果这个表已经有数据了，说明操作有误
		$sql = "select id from ".C('DB_PREFIX')."paystatus where orderNumber = '".$ordernumber."' and groupName = '".$qun."'";
		$data = $this->query($sql);	
		if($data)
		{
			return false;
		}
		else
		{
			$sql = "Update ".C('DB_PREFIX')."reportform SET payStatus='2' where orderNumber = '".$ordernumber."'and groupName = '".$qun."'";
			$data = $this->execute($sql);
			if($data)
			{
				$res = $this->UpdatePaystatus($goodsid,$ordernumber,$qun);
				if($res)
				{
					return true;
				}
			}
			else
			{
				return false;
			}
		}
		return false;
	}
	public function UpdatePaystatus($goodsid,$ordernumber,$qun)
	{
		$sql = "select goodsId,goodsTitle,orderNumber,commissionAmount,groupName,payStatus from ".C('DB_PREFIX')."reportform where orderNumber = '".$ordernumber."' and groupName = '".$qun."'";
		$data = $this->query($sql);
		if($data)
		{
			$data = $data[0];
			$goodsId = $data['goodsid'];
			$goodsTitle = $data['goodstitle'];
			$orderNumber = $data['ordernumber'];
			$commissionAmount = $data['commissionamount'];
			$groupName = $data['groupname'];
			$payStatus = $data['paystatus'];
			$payTime = date("Y-m-d h:i:s");
			//插入数据
			 $sql="INSERT INTO ".C('DB_PREFIX')."paystatus (goodsId,goodsTitle,orderNumber,commissionAmount,groupName,payStatus,payTime) 
		VALUES('".$goodsId ."','".$goodsTitle."','".$orderNumber."','".$commissionAmount."','".$groupName."','".$payStatus."','".$payTime."');";
			$data = $this->execute($sql);
			if($data)
			{//操作错误，应有滚回操作~~ 学习中....
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	
	}
	public function delPayInfo($goodsid,$ordernumber,$qun)
	{
			$sql = " DELETE FROM ".C('DB_PREFIX')."reportform  where orderNumber = '".$ordernumber."'and groupName = '".$qun."'";
			$data = $this->execute($sql);
			if($data)
			{
				return true;
			}
			else
			{
				return false;
			}	
	
	}
	


}
?>